﻿@{Lang lang = ViewBag.Lang;
}
@model IEnumerable<TGVR_Boot.DTO.TicketDTO>
<style>
    
</style>
<div class="left f-result" id="flighresult">
    <div id="OutBound" class="left">
        <h2 class="sub-title">
            @lang.OUTBOUND
        </h2>
        <p class="f-des">
            @lang.FROM <b class="f-city">@ViewData["fromcity"]</b> @lang.TO <b class="f-city">@ViewData["tocity"]</b>
            <br />@lang.FLIGHTDATE <b class="f-des-time">@(((DateTime)(ViewData["DatePickerDepartDate"])).ToString("dd/MM/yyyy"))</b>
            <br />
        </p>
        <p>
            + Giá vé đã bao gồm thuế và phí<br />
            + Giá vé chỉ áp dụng cho hình thức chuyển khoản<br />
            + Giao vé tại nhà phí 10.000 vnd
        </p>
        <style>
            .othertime
            {
                text-align: center;
            }
            .othertime .currenttime, .othertime span:hover
            {
                cursor: pointer;
                background-color: #D61321;
                font-size: 13px;
                color: White;
            }
            .othertime span
            {
                font-weight: bold;
                font-size: 13px;
                width: 90px;
                background-color: lavender;
                display: inline-block;
            }
        </style>
        <p class="othertime">
            @{
                DateTime dtTemp = (DateTime)ViewData["DatePickerDepartDate"];
            }
            <span>@dtTemp.AddDays(-3).ToString("dd/MM/yyyy")</span> <span>@dtTemp.AddDays(-2).ToString("dd/MM/yyyy")</span>
            <span>@dtTemp.AddDays(-1).ToString("dd/MM/yyyy")</span> <span class="currenttime">@dtTemp.ToString("dd/MM/yyyy")</span>
            <span>@dtTemp.AddDays(1).ToString("dd/MM/yyyy")</span> <span>@dtTemp.AddDays(2).ToString("dd/MM/yyyy")</span>
            <span>@dtTemp.AddDays(3).ToString("dd/MM/yyyy")</span>
        </p>
        <div class="loadding">
            <img alt="loadding" class="left" src='/Content/Images/Site/ajax_loader_red_128.gif' />
            <div class="des left f-des-time">
                @lang.SEARCHING
            </div>
            <br />
        </div>
        <div class="clear">
        </div>
        @(Html.Telerik().Grid(Model)
        .Name("ListResultOut")
        .Columns(columns =>
        {
            columns.Bound(o => o.FlightNo).Width(100).Title(lang.FIRM)
                .ClientTemplate("<img title='<#= FlightNo #>' altr='<#= FlightNo #>' src='/content/images/logo/<#= truncate(FlightNo,0, 2) #>.png'/>");
            columns.Bound(o => o.FlightNo).Width(100).Title(lang.FLIGHTNO)
                .ClientTemplate("<b><#= FlightNo #></b>").HtmlAttributes(new { @class = "f-no" });
            columns.Bound(o => o.DateStart).Width(250).Title(lang.TIME).Format("{0:HH:mm}")
                .ClientTemplate("<div class='f-time'><#= $.telerik.formatString('{0:HH:mm}', DateStart) #> - <#= $.telerik.formatString('{0:HH:mm}', DateEnd) #></div>");
            columns.Bound(o => o.Price).Width(200)
                .Title(lang.PRICE)
                .Format("{0:#,##0}")
                .ClientTemplate("<label class='f-price'><#= $.telerik.formatString('{0:n0}', Price) #></label> vnd")
                .HtmlAttributes(new { @class = "t-right" });

        })
                            .DataBinding(dataBinding => dataBinding.Ajax().Select("_ListResultOut", "FlightSearch",
                            new
                            {
                                SessionID = ViewBag.Key,
                                fromcity = ViewData["fromcity"],
                                tocity = ViewData["tocity"],
                                DatePickerDepartDate = ViewData["DatePickerDepartDate"],
                                DatePickerReturnDate = ViewData["DatePickerReturnDate"],
                                Adult = ViewData["Adult"],
                                Child = ViewData["Child"],
                                Baby = ViewData["Baby"]
                            }))
        .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
        .ClientEvents(e => e.OnDataBinding("showProgress").OnDataBound("hideProgress").OnError("onError"))
)
    </div>
    @if (ViewData["DatePickerReturnDate"] != null)
    {
        <div id="InBound" class="left">
            <h2 class="sub-title">
                @lang.INBOUND
            </h2>
            <p class="f-des">
                @lang.FROM <b class="f-city">@ViewData["tocity"]</b> @lang.TO <b class="f-city">@ViewData["fromcity"]</b>
                <br />@lang.FLIGHTDATE <b class="f-des-time">@(((DateTime)(ViewData["DatePickerReturnDate"])).ToString("dd/MM/yyyy"))</b>
                <br />
            </p>
            <p>
                + Giá vé đã bao gồm thuế và phí<br />
                + Giá vé chỉ áp dụng cho hình thức chuyển khoản<br />
                + Giao vé tại nhà phí 10.000 vnd
            </p>
            <p class="othertime">
                @{
        dtTemp = (DateTime)ViewData["DatePickerReturnDate"];
                }
                <span>@dtTemp.AddDays(-3).ToString("dd/MM/yyyy")</span> <span>@dtTemp.AddDays(-2).ToString("dd/MM/yyyy")</span>
                <span>@dtTemp.AddDays(-1).ToString("dd/MM/yyyy")</span> <span class="currenttime">@dtTemp.ToString("dd/MM/yyyy")</span>
                <span>@dtTemp.AddDays(1).ToString("dd/MM/yyyy")</span> <span>@dtTemp.AddDays(2).ToString("dd/MM/yyyy")</span>
                <span>@dtTemp.AddDays(3).ToString("dd/MM/yyyy")</span>
            </p>
            @(Html.Telerik().Grid(Model)
        .Name("ListResultIn")
        .Columns(columns =>
        {
            columns.Bound(o => o.FlightNo).Width(100).Title(lang.FIRM)
                .ClientTemplate("<img title='<#= FlightNo #>' altr='<#= FlightNo #>' src='/content/images/logo/<#= truncate(FlightNo,0, 2) #>.png'/>");
            columns.Bound(o => o.FlightNo).Width(100).Title(lang.FLIGHTNO)
                .ClientTemplate("<b><#= FlightNo #></b>").HtmlAttributes(new { @class = "f-no" });
            columns.Bound(o => o.DateStart).Width(250).Title(lang.TIME).Format("{0:HH:mm}")
                .ClientTemplate("<div class='f-time'><#= $.telerik.formatString('{0:HH:mm}', DateStart) #> - <#= $.telerik.formatString('{0:HH:mm}', DateEnd) #></div>");
            columns.Bound(o => o.Price).Width(200)
                .Title(lang.PRICE)
                .Format("{0:#,##0}")
                .ClientTemplate("<label class='f-price'><#= $.telerik.formatString('{0:n0}', Price) #></label> vnd")
                .HtmlAttributes(new { @class = "t-right" });

        })
                            .DataBinding(dataBinding => dataBinding.Ajax().Select("_ListResultIn", "FlightSearch",
                            new
                            {
                                SessionID = ViewBag.Key,
                                fromcity = ViewData["fromcity"],
                                tocity = ViewData["tocity"],
                                DatePickerDepartDate = ViewData["DatePickerDepartDate"],
                                DatePickerReturnDate = ViewData["DatePickerReturnDate"],
                                Adult = ViewData["Adult"],
                                Child = ViewData["Child"],
                                Baby = ViewData["Baby"]
                            }))
        .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
                .ClientEvents(e => e.OnDataBound("hideProgress1"))
)
        </div>
        <script>
            var canBind = false;

            function onDataBinding(e) {
                if (!canBind) {
                    e.preventDefault();
                }
            }
        </script>
    }
</div>
<div class="right r-margin5 r-selectedticket">
    @Html.Partial("Partials/LatestNews")
    <div class="block clear">
    </div>
    <div id="selectedticket">
        <h2>
            @lang.SELECTEDTICKET</h2>
        <hr />
        <div class="blog">
            <div class="select-out">
                <span class="l-label">@lang.OUTBOUND</span> <span class="l-price">0</span>
            </div>
            @if (ViewData["DatePickerReturnDate"] != null)
            {
                <div class="select-in">
                    <span class="l-label">@lang.INBOUND</span> <span class="l-price">0</span>
                </div>
            }
        </div>
        <hr />
        <div class="blog">
            <div class="select-sum">
                <span class="l-label">@lang.SUM</span> <span class="l-price">0</span>
            </div>
        </div>
        <form method="post" action="/flightsearch/booking">
        <input type="hidden" name="SessionID" value="@ViewBag.Key"/>
        <input type="hidden" name="DepartTicket" id="DepartTicket" value="" />
        <input type="hidden" name="ReturnTicket" id="ReturnTicket" value="" />
        <button type="submit" style="width: 203px; height: 30px; margin: 0; margin-left: 23px;
            padding: 4px">@lang.BOOKING</button>
        </form>
    </div>
</div>
<script>
    function showProgress(e) {
        $(".loadding").show();
        $("<div class='my-loading'> </div>").insertBefore(this.firstChild);
        var_dump(e);
    }

    function hideProgress(e) {
        
        $(".loadding").hide();
        canBind = true;
        $(".my-loading").remove();

        $('#ListResultOut.t-grid tr').click(function(e){

            $('#ListResultOut.t-grid tr').attr("class","");
            $(this).attr("class","selected");
            var p = $(this).find('.f-price').text();
            $('.select-out .l-price').html(p);
            calprice();
            var fNo = $(this).find('.f-no').text();
            $("#DepartTicket").val(fNo);
        });
        
         
          @if (ViewData["DatePickerReturnDate"] != null)
          {
                <text>
                var grid = $("#ListResultIn").data("tGrid");
                grid.ajaxRequest();
                </text>
          }      
    }
    function onError(e)
    {
        //alert("error");
        e.preventDefault();
        $(".loadding").hide();
        $(".my-loading").remove();
        window.location.href="/flightsearch/orderticket/"+@ViewBag.Key;
    }
    function hideProgress1(e) {
        $('#ListResultIn.t-grid tr').click(function(e){

            $('#ListResultIn.t-grid tr').attr("class","");
            $(this).attr("class","selected");
            var p = $(this).find('.f-price').text();
            $('.select-in .l-price').html(p);
            calprice();
            var fNo = $(this).find('.f-no').text();
            $("#ReturnTicket").val(fNo);
        });
    }

    function onError(e){
        
    }

    function truncate(input, start, length) {
        return input.substring(start, length);
    }

    function calprice(){
        var p1 = $('.select-out .l-price').text().replace(/,/g , "");
        //alert(p1);
        var p2 = $('.select-in .l-price').text().replace(/,/g , "");
        var sum = p1*1+p2*1;
        //sum = sum.replace(/(\d)(?=(\d{3})+\.)/g, "$1,");.format("#,#*");
        $('.select-sum .l-price').html(addCommas(sum));
    }

    $('html, body').animate({
            scrollTop: $("#flighresult").offset().top
        }, 2000);

    $('#OutBound .othertime span').click(function(e){
        $("#DatePickerDepartDate").val($(this).text());
        $("#flightSearch").submit();
    });
    $('#InBound .othertime span').click(function(e){
        $("#DatePickerReturnDate").val($(this).text());
        $("#flightSearch").submit();
    });
</script>
